//
//  UIUtils.m
//  funtown
//
//  Created by HLJ on 16/9/13.
//  Copyright © 2016年 FCSC. All rights reserved.
//

#import "UIUtils.h"
#import <SVProgressHUD/SVProgressHUD.h>
#import <MJRefresh/MJRefresh.h>

@implementation UIViewController (UIUtils)
+ (NSString *)ft_storyboardName { return @"Main"; }
+ (NSString *)ft_storyboardIdentifier { return NSStringFromClass(self); }

+ (instancetype)ft_instantiateFromStoryboard {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[self ft_storyboardName] bundle:nil];
    return [storyboard instantiateViewControllerWithIdentifier:[self ft_storyboardIdentifier]];
}

+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil) {
        
        return nil;
        
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError *err;
    
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                         
                                                        options:NSJSONReadingMutableContainers
                         
                                                          error:&err];
    
    if(err) {
        
        NSLog(@"json解析失败：%@",err);
        
        return nil;
        
    }
    
    return dic;
    
}



@end

@implementation UIUtils

+ (void)showHudLoadingNoMask{
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:[UIColor colorWithWhite:0. alpha:0.8]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setCornerRadius:8.];
    [SVProgressHUD show];
}

+ (void)showHudLoading{
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:[UIColor colorWithWhite:0. alpha:0.8]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setCornerRadius:8.];
    [SVProgressHUD show];
}

+ (void)showHudFailWithTint:(NSString*)tint{
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:[UIColor colorWithWhite:0. alpha:0.8]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setCornerRadius:8.];
    [SVProgressHUD setErrorImage:nil];
    [SVProgressHUD showErrorWithStatus:tint];
    
}

+ (void)showHudSuccessWithTint:(NSString*)tint{
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:[UIColor colorWithWhite:0. alpha:0.8]];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setCornerRadius:8.];
    [SVProgressHUD setErrorImage:[UIImage imageNamed:@"right"]];
    [SVProgressHUD showErrorWithStatus:tint];
    
}

+ (MJRefreshNormalHeader*)getMJRefreshHeaderWithSelctor:(SEL)action target:(id)VC{
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:VC refreshingAction:action];
    
    // 设置自动切换透明度(在导航栏下面自动隐藏)
    header.automaticallyChangeAlpha = YES;
    //header.arrowView.image = nil;//坑爹太丑了
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    return header;
}

@end
